package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import java.util.List;

/**
 * Created by hjz on 2018/3/29.
 *
 * RecyclerView基础适配器
 */

public abstract class RecyclerAdapter<T, VH extends RecyclerView.ViewHolder>
        extends RecyclerView.Adapter<VH>
{
    protected Context context;
    protected List<T> dataList;

    protected ClickListener<T> clickListener;
    protected ItemClickListener<T> itemClickListener;

    public void setClickListener(ClickListener<T> clickListener)
    {
        this.clickListener = clickListener;
    }

    public void setItemClickListener(ItemClickListener<T> itemClickListener)
    {
        this.itemClickListener = itemClickListener;
    }

    public RecyclerAdapter(Context context, List<T> dataList)
    {
        this.context = context;
        this.dataList = dataList;
    }

    public void setDataList(List<T> dataList)
    {
        this.dataList = dataList;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount()
    {
        if (dataList != null)
        {
            return dataList.size();
        }
        return 0;
    }

    public static abstract class BaseViewHolder<T> extends RecyclerView.ViewHolder
    {
        protected View itemView;

        public BaseViewHolder(View itemView)
        {
            super(itemView);
            this.itemView = itemView;
        }

        public abstract void bindData(T t);
    }

    public interface ClickListener<T>
    {
        void onClick(T t);
    }

    public interface ItemClickListener<T>
    {
        void onItemClick(T t);
    }

}
